<template>
	<view class="container">
		<!-- #ifdef H5 -->
		<uni-header></uni-header>
		<!-- #endif -->

		<view class="com-box">
			<view class="row">
				<text class="tit">修改昵称</text>
				<input class="input" type="text" v-model="userInfo.nickName" placeholder="请输入昵称" />
			</view>

			<!-- <view class="row">
				<text class="tit">修改性别</text>
				<picker class="tip" @change="sexChange" :value="sex" :range="sex">
					<view class="uni-input">
						<text>{{sex[sexIndex]}}</text>
						<text class="icon icon-arrow_right"></text>
					</view>
				</picker>
			</view> -->

			<view class="row area-row">
				<text class="tit">上传头像</text>
				<uni-upimg @change="getImageInfo" :upimg_preview="imageUrl" :upload_count="1"></uni-upimg>
			</view>

			<button type="primary" class="add-btn" @click="confirm" :disabled="submiting">保存</button>
		</view>

		<!-- #ifdef H5 -->
		<uni-footer></uni-footer>
		<!-- #endif -->
	</view>
</template>

<script>
	import uniHeader from '@/components/h5/uni-header.vue'
	import uniFooter from '@/components/h5/uni-footer.vue'
	import uniUpimg from '@/components/uni-upimg.vue'
	import {
		mapState,
		mapMutations
	} from 'vuex'
	export default {
		components: {
			uniHeader,
			uniFooter,
			uniUpimg
		},
		data() {
			return {
				sex: ['保密', '男', '女'],
				submiting: false,
				sexIndex: 0,
				imageUrl: [],
			}
		},
		computed: {
			...mapState(['userInfo']),
		},
		methods: {
			sexChange(e) {
				this.sexIndex = e.target.value
				this.userInfo.sex = this.sex[this.sexIndex]
			},
			getImageInfo(e) {
				this.imageUrl = e
				this.userInfo.imageUrl = e[0]
			},
			confirm() {
				if (!this.userInfo.nickName) {
					this.$api.msg('请输入昵称')
					return
				}
				// if (!this.userInfo.sex) {
				// 	this.$api.msg('请输入性别')
				// 	return
				// }
				if (!this.userInfo.imageUrl) {
					this.$api.msg('请上传头像')
					return
				}
				console.log(this.userInfo)
				this.$api.request('/zruser/updateUserInfo', {
					nickName: this.userInfo.nickName,
					imageUrl: this.userInfo.imageUrl
				}, {
					method: 'GET'
				}).then(res => {
					this.$api.msg('修改成功')
					this.$store.commit('login', this.userInfo)
          setTimeout(() => {
          	uni.navigateBack()
          }, 500)
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		padding-top: 20upx;
	}

	.row {
		.tit {
			width: 150upx;
		}

		.value {
			flex: 1;
		}

		.tip {
			flex-basis: 100%;
		}

		.uni-input {
			display: flex;
			justify-content: space-between;
		}
	}

	.area-row {
		height: inherit;
		padding: 20upx $base-row-spacing;
	}

	/* #ifdef H5 */
	@media screen and (min-width: 750px) {
		page {
			padding-top: 0;
		}

		.com-box {
			margin-top: 20px;
		}

		.row {
			.tit {
				width: 150px;
			}
		}

		.area-row {
			height: inherit;
			padding: 20px 30px;
		}
	}

	/* #endif */
</style>
